//
// Created by win10 on 2024/12/30.
//
#include <bits/stdc++.h>
using namespace std;
int n;
string s;
vector<string> strs;
int cmp(string a,string b){
    if(a.length()!=b.length()) return a.length()<b.length();
    return 0;
}
int main(){
    while(cin>>n){
        cin.ignore();
        strs.clear();
        while(n--){
            getline(cin,s);
            if(s=="stop") break;
            strs.push_back(s);
        }
        stable_sort(strs.begin(),strs.end(),cmp);
        for(string i:strs){
            cout<<i<<endl;
        }

    }
}